package studio7i.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import studio7i.excepcion.DAOExcepcion;
import studio7i.modelo.Instrumento;
import studio7i.modelo.Sala;
import studio7i.modelo.Servicio;
import studio7i.negocio.InstrumentoNegocio;
import studio7i.negocio.SalaNegocio;
import studio7i.negocio.ServicioNegocio;

/**
 * Servlet implementation class ArmadadoSala
 */
@WebServlet("/ArmadadoSala")
public class ArmadadoSala extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ArmadadoSala() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.processRequest(request, response);
	}
	protected void processRequest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		SalaNegocio neg = new SalaNegocio();
		InstrumentoNegocio negInstrumento=new InstrumentoNegocio();
		ServicioNegocio negServ=new ServicioNegocio();
		try
		{
			Collection<Sala> lista =neg.listarSalas_total();
			
			Collection<Instrumento> listaInstrumento=negInstrumento.listarInstrumentos();
			
			Collection<Servicio> listaServicio=negServ.listarservicios();
			
			// Guardar en el ambiente de request
			request.setAttribute("SalaListado", lista);
			
			request.setAttribute("InstrumentoListado", listaInstrumento);
			
			request.setAttribute("ServicioListado", listaServicio);
			
			
			RequestDispatcher rd = request.getRequestDispatcher("armarSala.jsp");
			rd.forward(request, response);
			
			
		}
		catch (DAOExcepcion e)
		{
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
	}
}
